#include <cstdio>
#include <cstring>
#include "head/superblock.h"
#include "head/inode.h"
#include "head/data.h"

//define the total size of the filesystem 16MB
#define TOTALSPACE 1024*1024*16
//define the block size 1KB
char buf[TOTALSPACE];

int main() {
    FILE* fp = fopen("fss", "wb+");

    // init all filesystem, and actually inode_bit_map and data_bit_map has been zero all
    memset(buf, 0, sizeof(buf));
    fwrite(buf, 1, TOTALSPACE, fp);

    // init super block
    SuperBlock* superBlock = new SuperBlock;
    fseek(fp, 0, SEEK_SET);
    fwrite(superBlock, sizeof(SuperBlock), 1, fp);

    // init root inode
    fseek(fp, superBlock->inode_bitmap_base, SEEK_SET);
    char c = 1;
    fwrite(&c, 1, 1, fp);

    Inode* inode = new Inode;
    inode->id = 0;
    inode->f_size = 0;
    inode->i_zone[0] = 0;
    inode->f_type = Type::DIR;
    fseek(fp, superBlock->inode_base, SEEK_SET);
    fwrite(inode, sizeof(Inode), 1, fp);

    fseek(fp, superBlock->data_bitmap_base, SEEK_SET);
    fwrite(&c, 1, 1, fp);

    fclose(fp);
}